package net.homeip.jcperera.nu.model.navigation;

import java.util.Set;

import javax.inject.Named;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import net.homeip.jcperera.nu.model.entity.PersistentEntity;

/**
 * Navigation Element, referring to a Navigation Item in a menu or tabbed-browser
 * 
 * @name Navigation Element class
 * @author julio.c.perera@gmail.com
 * @application nu
 * @since 0.1.0.0
 */
@Named(NavigationElement.componentName)
@Table(name = NavigationElement.tableName)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorValue(value = NavigationElement.tableName)
public class NavigationElement extends PersistentEntity
{
    // Required to implement Serializable interface
    private static final long     serialVersionUID = 8459693671454878433L;

    // CoreBase properties, for easy use from other components, as well as logging
    public static final int       runtimeLevel     = 1;
    public static final String    moduleName       = "config";
    public static final String    componentName    = "nu_config_model_navigation_element";

    // All persistent entities should specify a table name
    public static final String    tableName        = "NAVIGATION";

    @Basic
    @Column(name = "NAME")
    private String                name;

    @Basic
    @Column(name = "INFO")
    private String                info;

    @Basic
    @Column(name = "DESCRIPTION", length = 1024)
    private String                description;

    @Basic
    @Column(name = "URL", length = 1024)
    private String                url;

    @ManyToOne
    @JoinColumn(name = "PARENT", nullable = true)
    private NavigationElement     parent;

    @OneToMany(cascade = { CascadeType.REFRESH, CascadeType.REMOVE }, orphanRemoval = true, mappedBy = "parent")
    public Set<NavigationElement> children;

    public NavigationElement(String name, String info, String description, String url)
    {
        this.name = name;
        this.info = info;
        this.description = description;
        this.url = url;
    }

    public NavigationElement(String name, String info, String description)
    {
        this.name = name;
        this.info = info;
        this.description = description;
        this.url = "";
    }

    public NavigationElement(String name, String info)
    {
        this.name = name;
        this.info = info;
        this.description = "";
        this.url = "";
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getInfo()
    {
        return info;
    }

    public void setInfo(String info)
    {
        this.info = info;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public String getURL()
    {
        return url;
    }

    public void setURL(String url)
    {
        this.url = url;
    }

    public NavigationElement getParent()
    {
        return parent;
    }

    public void setParent(NavigationElement parent)
    {
        this.parent = parent;
    }

    public Set<NavigationElement> getChildren()
    {
        return children;
    }

    public void setChildren(Set<NavigationElement> children)
    {
        this.children = children;
    }
}
